import Vue from 'vue'
import VueRouter from 'vue-router'

const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
		alias: '/index',
        name: 'index',
        component: () => import('@/views/index.vue'),
		meta: { title: '首页',hideTabBar: false }
    },{
        path: '/mine',
        name: 'mine',
        component: () => import('@/views/mine.vue'),
		meta: { title: '我的',hideTabBar: false }
    },{
        path: '/mails',
        name: 'mails',
        component: () => import('@/views/mails.vue'),
		meta: { title: '寄售',hideTabBar: false }
    },{
        path: '/pages',
        name: 'pages',
        component: () => import('@/views/pages.vue'),
		meta: { title: '资讯',hideTabBar: false }
    },
	{
		path: '/login',
		name: 'login',
		 component: () => import('@/views/login.vue'),
		 meta: { title: '登入',hideTabBar: true }
	},
	{
		path: '/searchpage',
		name: 'searchpage',
		 component: () => import('@/views/searchpage.vue'),
		 meta: { title: '搜索',hideTabBar: true }
	},
	{
		path: '/detail',
		name: 'detail',
		 component: () => import('@/views/detail.vue'),
		 meta: { title: '商品详情页',hideTabBar: true }
	},
	{
		path: '/sell',
		name: 'sell',
		 component: () => import('@/views/sell.vue'),
		 meta: { title: '出售页',hideTabBar: true }
	},
	{
		path: '/nomobile',
		name: 'nomobile',
		 component: () => import('@/views/nomobile.vue'),
		 meta: { title: '出错了',hideTabBar: true }
	},
	{
		path: '/cart',
		name: 'cart',
		 component: () => import('@/views/cart.vue'),
		 meta: { title: '积分商城',hideTabBar: true }
	},
	{
		path: '/policies',
		name: 'policies',
		 component: () => import('@/views/policies.vue'),
		 meta: { title: '相关政策',hideTabBar: true }
	},
	{
		path: '/daohang',
		name: 'daohang',
		 component: () => import('@/views/daohang.vue'),
		 meta: { title: '站点管理',hideTabBar: true }
	},
	{
		path: '/success',
		name: 'success',
		 component: () => import('@/views/success.vue'),
		 meta: { title: '成功',hideTabBar: true }
	},
	{
		path: '/orders',
		name: 'orders',
		 component: () => import('@/views/orders.vue'),
		 meta: { title: '我的订单',hideTabBar: true }
	},
	{
		path: '/aichat',
		name: 'aichat',
		 component: () => import('@/views/aichat.vue'),
		 meta: { title: '智慧求助',hideTabBar: true }
	},
	{
		path: '/messages',
		name: 'messages',
		 component: () => import('@/views/messages.vue'),
		 meta: { title: '消息通知',hideTabBar: false }
	},
	{
		path: '/message',
		name: 'message',
		 component: () => import('@/views/message.vue'),
		 meta: { title: '对话',hideTabBar: true }
	},
	{
		path: '/userInfo',
		name: 'userInfo',
		 component: () => import('@/views/userInfo.vue'),
		 meta: { title: '资料卡',hideTabBar: true }
	},
	{
		path: '/rank',
		name: 'rank',
		 component: () => import('@/views/rank.vue'),
		 meta: { title: '我的排名',hideTabBar: true }
	},
	{
		path: '/pagedetail',
		name: 'pagedetail',
		 component: () => import('@/views/pagedetail.vue'),
		 meta: { title: '文章详情',hideTabBar: true }
	},
	{
		path: '/forecast',
		name: 'forecast',
		 component: () => import('@/views/forecast.vue'),
		 meta: { title: '农时预测',hideTabBar: true }
	},
	{
		path: '/survey',
		name: 'survey',
		 component: () => import('@/views/survey.vue'),
		 meta: { title: '问卷调查',hideTabBar: true }
	},
	{
		path: '/shopsetting',
		name: 'shopsetting',
		 component: () => import('@/views/shopsetting.vue'),
		 meta: { title: '店铺设置',hideTabBar: true }
	},
	{
		path: '/orderdetail',
		name: 'orderdetail',
		 component: () => import('@/views/orderdetail.vue'),
		 meta: { title: '订单详情',hideTabBar: true }
	},
	{
		path: '/address',
		name: 'address',
		 component: () => import('@/views/address.vue'),
		 meta: { title: '地址管理',hideTabBar: true }
	},
	{
		path: '/collectway',
		name: 'collectway',
		 component: () => import('@/views/collectway.vue'),
		 meta: { title: '回收去向',hideTabBar: true }
	},
	{
		path: '/personinfo',
		name: 'personinfo',
		 component: () => import('@/views/personinfo.vue'),
		 meta: { title: '个人信息',hideTabBar: true }
	},
	{
		path: '/name',
		name: 'name',
		 component: () => import('@/views/name.vue'),
		 meta: { title: '昵称修改',hideTabBar: true }
	},
	{
		path: '/phone',
		name: 'phone',
		 component: () => import('@/views/phone.vue'),
		 meta: { title: '手机号修改',hideTabBar: true }
	},
	{
		path: '/firstLogin',
		name: 'firstLogin',
		 component: () => import('@/views/firstLogin.vue'),
		 meta: { title: '资料完善',hideTabBar: true }
	},
	{
		path: '/publish',
		name: 'publish',
		 component: () => import('@/views/publish.vue'),
		 meta: { title: '发布文章',hideTabBar: true }
	},
	{
		path: '/game',
		name: 'game',
		 component: () => import('@/views/game.vue'),
		 meta: { title: '拼图游戏',hideTabBar: true }
	},
	{
		path: '/feedback',
		name: 'feedback',
		 component: () => import('@/views/feedback.vue'),
		 meta: { title: '意见反馈',hideTabBar: true }
	},
	{
		path: '/policies',
		name: 'policies',
		 component: () => import('@/views/policies.vue'),
		 meta: { title: '政策列表',hideTabBar: true }
	},
	{
		path: '/changepassword',
		name: 'changepassword',
		 component: () => import('@/views/changepassword.vue'),
		 meta: { title: '修改密码',hideTabBar: true }
	}
]

const router = new VueRouter({
    mode:'history',
    base: process.env.BASE_URL,
    routes
})

router.beforeEach((to, from, next) => {
	
	
	const userAgent = navigator.userAgent || navigator.vendor || window.opera;
	
	// 根据User-Agent检测是否为移动设备  
	const isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(userAgent);  
	
  if (!isMobile && to.path !== '/nomobile') {  
    // 如果不是移动设备且目标路由不是nomobile，则跳转到nomobile页面  
    next({ path: '/nomobile' });  
  }else if(isMobile && to.path == '/nomobile'){
	  if (to.meta.title) {
	    document.title = to.meta.title;  
	  } 
	   next({ path: '/index' });
  }else {  
    // 如果是移动设备或目标路由已经是nomobile，则正常导航  
    if (to.meta.title) {  
      document.title = to.meta.title;  
    }  
    next(); // 确保调用next()以继续导航  
  } 



})

export default router
